<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
	</head>

	<body>

		<div class="mui-content">

			<ul class="mui-table-view">
				<li class="mui-table-view-cell mui-media">
					<a id="link_myface" href="javascript:;">
						<span class="mui-pull-right mui-icon mui-icon-arrowright"
							style="line-height: 42px;color: lightgrey;margin-left: 3px;"></span>
						<img id="img_my_face" class="mui-media-object mui-pull-right" src="../../images/1.jpg">
						<div class="mui-media-body" style="line-height: 42px;font-size: 16px;">
							头像
						</div>
					</a>
				</li>
				<li class="mui-table-view-cell mui-media">
					<a id="change_password" href="javascript:;">
						<span class="mui-pull-right mui-icon mui-icon-arrowright"
							style="color: lightgrey;margin-left: 3px;"></span>
						<div class="mui-media-body">
							修改密码
						</div>
					</a>
				</li>
				<li class="mui-table-view-cell mui-media">
					<a href="javascript:;">
						<span id="s_name" class="mui-pull-right" style="color: gray;font-size: 14px;">aaa</span>
						<div class="mui-media-body">
							姓名
						</div>
					</a>
				</li>
				<li class="mui-table-view-cell mui-media">
					<a href="javascript:;">
						<span id="s_number" class="mui-pull-right" style="color: gray;font-size: 14px;">1234</span>
						<div class="mui-media-body">
							学号
						</div>
					</a>
				</li>
			</ul>

			<br />

			<ul class="mui-table-view">

				<li class="mui-table-view-cell mui-media" style="text-align: center;">
					<a id="link_logout" href="javascript:;">
						<div class="mui-media-body">
							退出登录
						</div>
					</a>
				</li>

			</ul>

		</div>

		<script src="../../js/mui.min.js"></script>
		<script src="../../js/app.js"></script>
		<script type="text/javascript">
			mui.init();

			mui.plusReady(function() {
				// 获得当前的 webview ,刷新当前用户信息
				var meWebview = plus.webview.currentWebview();
				meWebview.addEventListener("show", function() {
					refreshUserInfo();
				});

				// 页面跳转我的头像
				var link_myface = document.getElementById("link_myface");
				link_myface.addEventListener("tap", function() {
					mui.openWindow("studentFace.html", "studentFace.html");
				});

				// 页面跳转修改密码
				var change_password = document.getElementById("change_password");
				change_password.addEventListener("tap", function() {
					mui.openWindow({
						url: "studentPasswordChange.html",
						id: "studentPasswordChange.html",
						createNew: true
					});
				});

				// 用户退出登录
				var link_logout = document.getElementById("link_logout");
				link_logout.addEventListener("tap", function() {
					app.userLogout();
					mui.openWindow({
						url: "../../login.html",
						id: "login.html"
					});
				});
				
				window.addEventListener("refresh", function() {
					refreshUserInfo();
				});
			});

			function refreshUserInfo() {
				var user = app.getGlobalUserInfo();
				console.log(user);
				if (user != null) {
					var faceImage = user.head_portrait_url_small;
					var name = user.name;
					var number = user.user_id;

					var s_name = document.getElementById("s_name");
					var s_number = document.getElementById("s_number");

					s_name.innerHTML = name;
					s_number.innerHTML = number;

					if (app.isNotNull(faceImage)) {
						var img_my_face = document.getElementById("img_my_face");
						img_my_face.src = app.imgServerUrl + faceImage;
					}
				}
			}
		</script>
	</body>

</html>
